
package managedbeans.fileshare;


import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import langresources.ResourcesController;
import managedbeans.GenericForumBean;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;
import utils.dataaccess.IOUtil;


@ManagedBean(name="fileUploadBean")
@SessionScoped
public class FileUploadBean extends GenericForumBean implements Serializable{

    private byte[] fileBytes = null;
    private String uploadStatusMessage = "";
    
    public FileUploadBean() {

    }
    
    public void handleFileUpload(FileUploadEvent evt){
            UploadedFile uploadedFile = evt.getFile();
            String fileName  = uploadedFile.getFileName();
            IOUtil.saveFile(uploadedFile.getContents(), fileName);
            uploadStatusMessage = ResourcesController.extractResource("LAST_DOWNLOADED_FILE")+": "+getTimestamp();
    }


    public byte[] getFileBytes() {
        return fileBytes;
    }

    public void setFileBytes(byte[] fileBytes) {
        this.fileBytes = fileBytes;
    }

    public String getUploadStatusMessage() {
        return uploadStatusMessage;
    }

    public void setUploadStatusMessage(String uploadStatusMessage) {
        this.uploadStatusMessage = uploadStatusMessage;
    }
    
    

    
}
